package net.lab1024.sa.admin.module.business.category.domain.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.Data;

import java.util.List;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RetroResponse {
    @JsonProperty("result_code")
    private Integer resultCode;

    @JsonProperty("data")
    private RetroResult2 data;

    @JsonProperty("message")
    private String message;

    @Override
    public String toString() {
        try {
            ObjectMapper mapper = new ObjectMapper();
            mapper.enable(SerializationFeature.INDENT_OUTPUT);
            return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this);
        } catch (JsonProcessingException e) {
            return "{\"result_code\": null, \"message\": \"序列化失败\"}";
        }
    }

    @Data
    @JsonInclude(JsonInclude.Include.NON_NULL)
    public static class RetroResult2 {
        @JsonProperty("nodes")
        private List<Node> nodes;

        @JsonProperty("edges")
        private List<Edge> edges;

        @Data
        @JsonInclude(JsonInclude.Include.NON_NULL)
        public static class Node {
            @JsonProperty("id")
            private String id;

            @JsonProperty("data")
            private NodeData data;

            @Data
            @JsonInclude(JsonInclude.Include.NON_NULL)
            public static class NodeData {
//                @JsonProperty("level")
//                private Integer level;

                @JsonProperty("smiles")
                private String smiles;

                @JsonProperty("image")
                private String image;

                @JsonProperty("in_stock")
                private Boolean inStock;

                @JsonProperty("MW")
                private Double mw;

                @JsonProperty("score")
                private Double score;

                @JsonProperty("template")
                private String template;

                @JsonProperty("template_id")
                private Integer templateId;

                @JsonProperty("condition")
                private List<String> condition;

                @JsonProperty("text")
                private String text;
                //
                //                @JsonProperty("elements")
                //                @JsonInclude(JsonInclude.Include.NON_EMPTY)
                //                private List<String> elements;
            }
        }

        @Data
        @JsonInclude(JsonInclude.Include.NON_NULL)
        public static class Edge {
            @JsonProperty("source")
            private String source;

            @JsonProperty("target")
            private String target;

            @JsonProperty("data")
            private EdgeData data;

            @Data
            @JsonInclude(JsonInclude.Include.NON_NULL)
            public static class EdgeData {

                @JsonProperty("score")
                private Double score;

                @JsonProperty("template")
                private String template;

                @JsonProperty("template_id")
                private Integer templateId;

                @JsonProperty("condition")
                private List<String> condition;

                @JsonProperty("text")
                private String text;

                @JsonProperty("color")
                private String color;

                @JsonProperty("merge")
                @JsonInclude(JsonInclude.Include.NON_EMPTY)
                private String merge;

                //                @JsonProperty("condition")
                //                private List<String> condition;


            }
        }
    }
}